package egal;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


public class test extends JFrame {

	private JPanel contentPane;
	private final JButton Button_3_3 = new JButton("");
	private final JButton button_1_2 = new JButton("");
	private final JButton button_3_2 = new JButton("");
	private final JButton button_2_3 = new JButton("");
	private final JButton button_1_3 = new JButton("");
	private final JButton button_2_1 = new JButton("");
	private final JButton button_3_1 = new JButton("");
	private final JButton button_1_1 = new JButton("");
	private final JButton button_2_2 = new JButton("");

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					test frame = new test();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public test() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 305, 330);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		Button_3_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				do_Button_3_3_actionPerformed(e);
			}
		});
		Button_3_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				do_button_3_3_mouseClicked(arg0);
			}
		});
		Button_3_3.setBounds(200, 200, 100, 100);
		contentPane.add(Button_3_3);
		button_1_2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				do_button_1_2_mouseClicked(arg0);
			}
		});
		button_1_2.setBounds(100, 0, 100, 100);
		
		contentPane.add(button_1_2);
		button_3_2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				do_button_3_2_mouseClicked(arg0);
			}
		});
		button_3_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
			}
		});
		button_3_2.setBounds(100, 200, 100, 100);
		
		contentPane.add(button_3_2);
		button_2_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				do_button_2_3_mouseClicked(arg0);
			}
		});
		button_2_3.setBounds(200, 100, 100, 100);
		
		contentPane.add(button_2_3);
		button_1_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {

				do_Button_1_3_mouseClicked(arg0);
			}
		});
		
		button_1_3.setBounds(200, 0, 100, 100);
		
		contentPane.add(button_1_3);
		button_2_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				do_button_2_1_mouseClicked(arg0);
			}
		});
		button_2_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			}
		});
		button_2_1.setBounds(0, 100, 100, 100);
		
		contentPane.add(button_2_1);
		button_3_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				do_button_3_1_mouseClicked(arg0);
			}
		});
		button_3_1.setBounds(0, 200, 100, 100);
		
		contentPane.add(button_3_1);
		button_1_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				do_button_1_1_mouseClicked(arg0);
			}
		});
		button_1_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			}
		});
		button_1_1.setBounds(0, 0, 100, 100);
		
		contentPane.add(button_1_1);
		button_2_2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				do_button_2_2_mouseClicked(arg0);
			}
		});
		button_2_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				
			}
		});
		button_2_2.setBounds(100, 100, 100, 100);
		
		contentPane.add(button_2_2);
	}

	
	private void zug(JButton clicked , MouseEvent arg0) {
		if (arg0.getModifiers()==16){
			clicked.setText("X");
		}
		else if (arg0.getModifiers()==4){
			clicked.setText("O");
		}
		else{
			System.out.println("Only leftclick or rightcklick allowed");
			System.out.println("left click is X");
			System.out.println("right click is O");
		}
		//clicked.setText("X");
		//System.out.println(arg0.getModifiers());
	}
	
	protected void do_button_1_1_mouseClicked(MouseEvent arg0) {
		JButton clicked=(JButton)arg0.getSource();
		zug(clicked,arg0);
	}
	protected void do_button_1_2_mouseClicked(MouseEvent arg0) {
		JButton clicked=(JButton)arg0.getSource();
		zug(clicked,arg0);
	}
	protected void do_Button_1_3_mouseClicked(MouseEvent arg0) {
		JButton clicked=(JButton)arg0.getSource();
		zug(clicked,arg0);
	}
	protected void do_button_2_1_mouseClicked(MouseEvent arg0) {
		JButton clicked=(JButton)arg0.getSource();
		zug(clicked,arg0);
	}
	protected void do_button_2_2_mouseClicked(MouseEvent arg0) {
		JButton clicked=(JButton)arg0.getSource();
		zug(clicked,arg0);
	}
	protected void do_button_2_3_mouseClicked(MouseEvent arg0) {
		JButton clicked=(JButton)arg0.getSource();
		zug(clicked,arg0);
	}
	protected void do_button_3_1_mouseClicked(MouseEvent arg0) {
		JButton clicked=(JButton)arg0.getSource();
		zug(clicked,arg0);
	}
	protected void do_button_3_2_mouseClicked(MouseEvent arg0) {
		JButton clicked=(JButton)arg0.getSource();
		zug(clicked,arg0);
	}
	protected void do_button_3_3_mouseClicked(MouseEvent arg0) {
		JButton clicked=(JButton)arg0.getSource();
		zug(clicked,arg0);
	}
	protected void do_Button_3_3_actionPerformed(ActionEvent e) {
	}
}
